﻿using System;
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class BaseData 
{
    [JsonProperty]
    private float[] m = new float[6] { 0, 0, 0, 0, 0, 0 };

    /// <summary>
    /// 基础数值,long-double
    /// </summary>
    [JsonIgnore]
    public float baseData
    {
        get { return m[0]; }
        private set { m[0] = value; }
    }

    /// <summary>
    /// 基础数值增量,long-double
    /// </summary>
    [JsonIgnore]
    public float add
    {
        get { return m[1]; }
        private set { m[1] = value; }
    }

    /// <summary>
    /// 基础数值增益,long-double,该值代表百分之n
    /// </summary>
    [JsonIgnore]
    public float pct
    {
        get { return m[2]; }
        private set { m[2] = value; }
    }

    /// <summary>
    /// 最终数值增量,long-double
    /// </summary>
    [JsonIgnore]
    public float finalAdd
    {
        get { return m[3]; }
        private set { m[3] = value; }
    }

    /// <summary>
    /// 最终增益,long-double,该值代表百分之n
    /// </summary>
    [JsonIgnore]
    public float finalPct
    {
        get { return m[4]; }
        private set { m[4] = value; }
    }

    [JsonIgnore]
    public float Final
    {
        get { return m[5]; }
        private set { m[5] = value; }
    }

    public BaseData()
    {
    }

    /// <summary>
    /// 直接赋给该属性一个基础值
    /// </summary>
    /// <param name="m_base"></param>
    public BaseData(float m_base)
    {
        baseData = m_base;
        add = 0;
        pct = 0;
        finalAdd = 0;
        finalPct = 0;
        Final = m_base;
    }

    /// <summary>
    /// 最终值=((基础数值+基础增量)*(1+基础增益倍数)+最终增量)*(1+最终增益倍数)
    /// </summary>
    /// <param name="baseData">基础数值</param>
    /// <param name="add">基础增量</param>
    /// <param name="pct">基础增益倍数</param>
    /// <param name="finalAdd">最终增量</param>
    /// <param name="finalPct">最终增益倍数</param>
    public BaseData(float baseData, float add, float pct, float finalAdd, float finalPct)
    {
        this.baseData = baseData;
        this.add = add;
        this.pct = pct;
        this.finalAdd = finalAdd;
        this.finalPct = finalPct;
        SulFianl();
    }
    /// <summary>
    /// 复制一个FightDataBase
    /// </summary>
    /// <param name="fightData">被复制的对象</param>
    public BaseData(BaseData fightData)
    {
        baseData = fightData.baseData;
        add = fightData.add;
        pct = fightData.pct;
        finalAdd = fightData.finalAdd;
        finalPct = fightData.finalPct;
        SulFianl();
    }

    public static BaseData operator +(BaseData data1, BaseData data2)
    {
        BaseData data = new BaseData();
        data.baseData = data1.baseData + data2.baseData;
        data.add = data1.add + data2.add;
        data.pct = data1.pct + data2.pct;
        data.finalAdd = data1.finalAdd + data2.finalAdd;
        data.finalPct = data1.finalPct + data2.finalPct;
        data.SulFianl();
        return data;
    }

    public static BaseData operator -(BaseData data1, BaseData data2)
    {
        BaseData data = new BaseData();
        data.baseData = data1.baseData - data2.baseData;
        data.add = data1.add - data2.add;
        data.pct = data1.pct - data2.pct;
        data.finalAdd = data1.finalAdd - data2.finalAdd;
        data.finalPct = data1.finalPct - data2.finalPct;
        data.SulFianl();
        return data;
    }

    public static bool operator >(BaseData data1, BaseData data2)
    {
        return data1.Final > data2.Final;
    }

    public static bool operator <(BaseData data1, BaseData data2)
    {
        return data1.Final < data2.Final;
    }

    /// <summary>
    /// 隐式装换成float
    /// <para>直接返回Final值</para>
    /// </summary>
    /// <param name="baseData"></param>
    public static implicit operator float(BaseData baseData)
    {
        return baseData.Final;
    }

    private void SulFianl()
    {
        float baseData = this.baseData;
        float add = this.add;
        float pct = this.pct;
        float finalAdd = this.finalAdd;
        float finalPct = this.finalPct;

        Final = ((baseData + add) * (1f + pct)  + finalAdd) * (1 + finalPct);
    }

}
